﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HelperClass.cs" company="Jens Horstmann">
//   Copyright (c) Jens Horstmann. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace MiniMusicPlayer.Classes
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    /// <summary>
    /// The helper class.
    /// </summary>
    public static class HelperClass
    {
        /// <summary>
        /// The shuffle.
        /// </summary>
        /// <param name="list">
        /// The list.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        public static void Shuffle<T>(this IList<T> list)
        {
            var rng = new Random();

            var n = list.Count;
            while (n > 1)
            {
                n--;
                var k = rng.Next(n + 1);
                var value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }

        /// <summary>
        /// The string array to string.
        /// </summary>
        /// <param name="array">
        /// The array.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string StringArrayToString(string[] array)
        {
            if (array != null && array.Length > 0)
            {
                var sb = new StringBuilder();

                foreach (var s in array)
                {
                    sb.Append(s);
                    sb.Append(", ");
                }

                var resultString = sb.ToString();

                return resultString.Remove(resultString.Length - 2);
            }

            return string.Empty;
        }
    }
}